package com.pda.xinma.ui.home;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.pda.xinma.R;
import com.pda.xinma.bean.ScanBean;
import com.pda.xinma.bean.ScanResultBean;
import com.pda.xinma.contract.HomeContract;
import com.pda.xinma.presenter.HomePresenter;
import com.pda.xinma.utils.StringConfig;
import com.pda.xinma.utils.UserUtils;
import com.pda.xinma.view.ScanButView;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.wangshen.base.app.AppActivityKey;
import com.wangshen.base.ui.mvp.base.ui.BaseMvpActivity;
import com.wangshen.base.util.ToastUtils;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

@Route(path = AppActivityKey.HOMEACTIVITY)
public class HomeActivity extends BaseMvpActivity<HomePresenter> implements HomeContract.View {

    @BindView(R.id.iv_admin)
    ImageView ivAdmin;
    @BindView(R.id.tv_admin)
    TextView tvAdmin;
    @BindView(R.id.tv1)
    TextView tv1;
    @BindView(R.id.switch_warehouse)
    RelativeLayout switchWarehouse;
    @BindView(R.id.tv_total_location)
    TextView tvTotalLocation;
    @BindView(R.id.tv_used)
    TextView tvUsed;
    @BindView(R.id.tv_occupancy_rate)
    TextView tvOccupancyRate;
    @BindView(R.id.ll_manual_pallet)
    LinearLayout llManualPallet;
    @BindView(R.id.ll_spot_check)
    LinearLayout llSpotCheck;
    @BindView(R.id.ll_sampling_inspection_results)
    LinearLayout llSamplingInspectionResults;
    @BindView(R.id.ll_manual_inventory)
    LinearLayout llManualInventory;
    @BindView(R.id.ll_manual_outbound)
    LinearLayout llManualOutbound;
    @BindView(R.id.location_query)
    ImageView locationQuery;
    @BindView(R.id.ll_stock_taking)
    LinearLayout llStockTaking;
    @BindView(R.id.ll_scan_code_query)
    LinearLayout llScanCodeQuery;
    @BindView(R.id.ll_location_query)
    LinearLayout llLocationQuery;
    @BindView(R.id.ll_manual_picking)
    LinearLayout llManualPicking;
    @BindView(R.id.ll_library_of_warehouse)
    LinearLayout llLibraryOfWarehouse;
    @BindView(R.id.ll_movement)
    LinearLayout llMovement;
    @BindView(R.id.ll_putaway)
    LinearLayout llPutaway;
    @BindView(R.id.ll_failed_manager)
    LinearLayout llFailedManager;
    @BindView(R.id.ll_scan_demo)
    LinearLayout llScanDemo;
    @BindView(R.id.search)
    ScanButView search;

    @Override
    public HomePresenter getPresenter() {
        return new HomePresenter();
    }

    @Override
    public int getView() {
        return R.layout.activity_home;
    }

    @Override
    public void initView() {
        tvAdmin.setText(UserUtils.getInstance().getUserBean().getUserName());
    }

    @Override
    public void initLinsenterner() {
        Intent intent = new Intent ("ACTION_BAR_SCANCFG");
        intent.putExtra("EXTRA_SCAN_MODE", 3);
        intent.putExtra("EXTRA_SCAN_AUTOENT", 1);
        mContext.sendBroadcast(intent);

    }

    @Override
    protected void onResume() {
        super.onResume();
        search.setScanCallBack(new ScanButView.ScanCallBack() {
            @Override
            public void callBack(ScanBean scanBean) {
                if (scanBean.getCode().contains("order")) {
                    int lenth = scanBean.getCode().indexOf("A");
                    String order = scanBean.getCode().substring(lenth + 1);
                    Bundle bundle=new Bundle();
                    bundle.putString(StringConfig.STORAGEBINID,order);
                    startIntent(AppActivityKey.SEARCHACTIVITY,bundle);
                } else {
                    presenter.scanTheQRCodeToVerify(scanBean.getCode());
                }
            }
        });
    }

    @Override
    protected void onPause() {
        super.onPause();
        search.setScanCallBack(null);
    }

    @Override
    public void getData() {


    }



    @Override
    public void showMessage(String msg) {
        super.showMessage(msg);
    }


    @OnClick({R.id.ll_manual_pallet, R.id.ll_spot_check, R.id.ll_sampling_inspection_results, R.id.ll_manual_inventory, R.id.ll_manual_outbound, R.id.ll_stock_taking, R.id.ll_scan_code_query, R.id.ll_location_query})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_manual_pallet:
                startIntent(AppActivityKey.INSTOREGEACTIVITY);
                break;
            case R.id.ll_spot_check:
                startIntent(AppActivityKey.PICKINGACTIVITY);
                break;
            case R.id.ll_sampling_inspection_results:
                startIntent(AppActivityKey.MACHINECALLACTIVITY);
                break;
            case R.id.ll_manual_inventory:
                startIntent(AppActivityKey.MANMADEACTIVITY);
                break;
            case R.id.ll_manual_outbound:
                startIntent(AppActivityKey.FULLINVENTORYLISTACTIVITY);
                break;
            case R.id.ll_stock_taking:
                startIntent(AppActivityKey.INPRODUCTIONSTOREGEACTIVITY);
                break;
            case R.id.ll_scan_code_query:
                startIntent(AppActivityKey.AGVMOVEACTIVITY);
                break;
            case R.id.ll_location_query:
                startIntent(AppActivityKey.DEMONSTRATEACTIVITY);
                break;
        }
    }

    @Override
    public void setScanBean(ScanResultBean scanBean) {
        if (scanBean.getType().equals("KW")) {
            Bundle bundle=new Bundle();
            bundle.putString(StringConfig.CODE,scanBean.getCode());
            startIntent(AppActivityKey.SEARCHACTIVITY,bundle);
        } else {
            ToastUtils.showToast(mContext, "请扫接驳工位");

        }
    }

    /*@OnClick(R.id.llscatteredmove)
    public void onViewClicked10() {
        startIntent(AppActivityKey.SCATTEREDMOVEACTIVITY);
    }


    @OnClick(R.id.ll_agvputaway)
    public void onViewClicked11() {
        startIntent(AppActivityKey.AVGPUTAWAYLISTACTIVITY);
    }


    @OnClick({R.id.ll_agv_move, R.id.ll_avg_delivery})
    public void onViewClicked12(View view) {
        switch (view.getId()) {
            case R.id.ll_agv_move:
                startIntent(AppActivityKey.AGVMOVEMENTACTIVITY);
                break;
            case R.id.ll_avg_delivery:
                startIntent(AppActivityKey.AGVDELIVERYLISTACTIVITY);
                break;
        }
    }
*/

}
